//
//  CZQPublishChoseView.m
//  coachmanage
//
//  Created by 众拳科技 on 2018/3/30.
//  Copyright © 2018年 众拳科技. All rights reserved.
//

#import "CZQPublishChoseView.h"

@implementation CZQPublishChoseView
-(id)initWithFrame:(CGRect)frame{
    
    CGRect initialFrame;
    
    if (CGRectIsEmpty(frame)) {
        
        initialFrame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        
    } else {
        
        initialFrame = frame;
    }
    
    self = [super initWithFrame:initialFrame];
    
    if (self) {
        
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.4];
        [self addSubview:alphaView];
        self.alphaView = alphaView;
        
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"发布动态";
        titleLabel.font = MidBigFont;
        titleLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [whiteView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIButton *weChatBtn = [[UIButton alloc] init];
        [weChatBtn setImage:@"icon_share_wechat"];
        [weChatBtn setTitle:@"小视频"];
        [weChatBtn addTarget:self action:@selector(hiddenWithAnimation)];
        weChatBtn.titleLabel.font = MidFont;
        [weChatBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        [whiteView addSubview:weChatBtn];
        self.weChatBtn = weChatBtn;
        
        UIButton *friendBtn = [[UIButton alloc] init];
        [friendBtn setImage:@"icon_share_circlefriends"];
        [friendBtn setTitle:@"动态"];
        [friendBtn addTarget:self action:@selector(hiddenWithAnimation)];
        friendBtn.titleLabel.font = MidFont;
        [friendBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        [whiteView addSubview:friendBtn];
        self.friendBtn = friendBtn;
        
//        UIButton *linkBtn = [[UIButton alloc] init];
//        [linkBtn setImage:@"icon_share_clink"];
//        [linkBtn setTitle:@"复制链接"];
//        linkBtn.titleLabel.font = MidFont;
//        [linkBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
//        [whiteView addSubview:linkBtn];
//        self.linkBtn = linkBtn;
        
        UIButton *closeBtn = [[UIButton alloc] init];
        [closeBtn setImage:@"pop_icon_close"];
        [closeBtn addTarget:self action:@selector(hiddenWithAnimation)];
        [whiteView addSubview:closeBtn];
        self.closeBtn = closeBtn;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self);
    }];
    
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.left.width.mas_equalTo(self);
    }];
    
    [self.closeBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.whiteView).offset(-10);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    [self.weChatBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(self.closeBtn.mas_top).mas_equalTo(-30);
        
        make.left.mas_equalTo(self.whiteView).offset(20);
        
    }];
    [self.weChatBtn titleBelowTheImageWithSpace:8];
    
    [self.friendBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
//        make.centerX.mas_equalTo(self.whiteView);
        
        make.width.mas_equalTo(self.weChatBtn);
        
        make.left.mas_equalTo(self.weChatBtn.mas_right);
        
        make.right.mas_equalTo(self.whiteView).offset(-20);
        
        make.bottom.mas_equalTo(self.weChatBtn);
    }];
    [self.friendBtn titleBelowTheImageWithSpace:8];
    
    
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.whiteView).offset(20);
        make.centerX.mas_equalTo(self.whiteView);
        make.bottom.mas_equalTo(self.weChatBtn.mas_top).offset(-20);
    }];
    
}

- (void)showWithAnimation {
    [self addViews];
    self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    CGFloat height = self.whiteView.frame.size.height;
    self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT - height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
    }];
    
}

- (void)hiddenWithAnimation {
    CGFloat height = self.whiteView.frame.size.height;
    [UIView animateWithDuration:0.25 animations:^{
        self.whiteView.center = CGPointMake(SCREEN_WIDTH / 2, SCREEN_HEIGHT + height / 2);
        self.alphaView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.0];
    } completion:^(BOOL finished) {
        [self hiddenViews];
    }];
}

- (void)addViews {
    
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [window addSubview:self];
}

- (void)hiddenViews {
    
    [self removeFromSuperview];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
